<template>
	<view>
		<view class="bindingWx">
			<view class="bindingWx_text">
				<text>绑定微信</text>
			</view>
		</view>
		<view class="login_img">
			<image src="http://106.14.56.171:15016/images/login/badng.png" mode="widthFix"></image>
			<view class=""><text>你尚未绑定微信，绑定登录更便捷</text></view>
		</view>
		<view class="login">
			<view @click="bindWechat"><text>绑定微信</text></view>
		</view>
		<Loading :loadingShow="loading"></Loading>
	</view>
</template>

<script>
	import Loading from '@/components/loading/loading.vue'
	export default {
		data() {
			return {
				loading: false, // 加载中
			};
		},
		components: {
			Loading,
		},
		methods: {
			// 绑定微信接口
			bindWechat() {
				uni.login({
					provider: 'weixin',
					success: (res) => {
						console.log(res, '=====================1');
						if (res.errMsg == "login:ok") {
							let data = {
								// #ifdef APP-PLUS
								unionId: res.authResult.unionid
								// #endif
								// #ifdef MP-WEIXIN
								code: res.code,
								// #endif
							};
							console.log(data, '=====================0');
							this.$httpNew
								.post('authApi/user/bindWx', data)
								.then(res => {
									console.log(res, '=====================2');
									if (res == null) {
										uni.showToast({
											title: '微信绑定成功',
											icon: 'none'
										});
										this.loading = true
										uni.navigateBack({
											url: '/pages/user/setting'
										})
									}
								});
						} else {
							this.loading = false
							uni.showToast({
								title: '微信登录异常，请尝试其他形式登录',
								icon: 'none'
							});
						}
					}
				});
			},
			bindIos(){
				let _that = this
				uni.login({
					provider: 'apple',
					success: function(loginRes) {
						// 登录成功  
						uni.getUserInfo({
							provider: 'apple',
							success(res) {
								// 获取用户信息成功  
								if (res.errMsg == 'getUserInfo:ok') {
									
									// authApi/user/bindIOSInput
									_that.$httpNew
										.post('authApi/user/bindIOSInput', {
											openId:res.userInfo.openId
										}).then(resIos=>{
											console.log(resIos,'苹果信息成功');
										})
								}
							}
						})
					},
					fail: function(err) {
						console.log(err)
					}
				});
				
			}
		}
	};
</script>

<style lang="less" scpoed>
	.bindingWx {
		padding: 0 40rpx;
	}

	.bindingWx text {
		color: #000;
		font-weight: 500;
		font-size: 50rpx;
		display: block;
		line-height: 250rpx;
	}

	.bindingWx_text {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.login_img {
		width: 100%;
		height: 300rpx;
		text-align: center;

		>view {
			margin-top: 20rpx;
		}
	}

	.login_img image {
		width: 80%;
	}

	.login_img text {
		font-size: 31rpx;
		font-weight: 400;
		color: #6c6c6c;
	}

	.login {
		margin-top: 110rpx;
		width: 100%;
		height: 140rpx;
		text-align: center;

		// background-color: aqua;
		>view {
			margin: auto;
			line-height: 90rpx;
			color: #fff;
			font-size: 36rpx;
			margin-top: 180rpx;
			width: 90%;
			height: 90rpx;
			background-color: #c5001a;
			border-radius: 50rpx;
		}


	}

	.login .login_btn {
		line-height: 90rpx;
		color: #fff;
		font-size: 36rpx;
		margin-top: 180rpx;
		width: 90%;
		height: 90rpx;
		background-color: #c5001a;
		border-radius: 50rpx;
	}
</style>
